Why if i have more than 1 form in the same page with the same input file ID it is take just the first ID? - ajax

I have more than form in the same file like
<form name="myForm">
<input type="hidden" value="1" id="lastphp">
<a onclick="ajaxFunction()" class="folloo">
</form>
<form name="myForm">
<input type="hidden" value="2" id="lastphp">
<a onclick="ajaxFunction()" class="folloo">
</form>
<form name="myForm">
<input type="hidden" value="3" id="lastphp">
<a onclick="ajaxFunction()" class="folloo">
</form>
<form name="myForm">
<input type="hidden" value="4" id="lastphp">
<a onclick="ajaxFunction()" class="folloo">
</form>
but when I click on any link it always take the first ID which is 1??

An ID needs to be unique to the page, as it is a key for that element.
Why not change id="lastphp" to class="lastphp" and pass the form to the function?
<form name="myForm">
<input type="hidden" value="1" class="lastphp">
<a onclick="ajaxFunction(this.parentNode)" class="folloo">Test</a>
</form>
<form name="myForm">
<input type="hidden" value="2" class="lastphp">
<a onclick="ajaxFunction(this.parentNode)" class="folloo">Test</a>
</form>
<form name="myForm">
<input type="hidden" value="3" class="lastphp">
<a onclick="ajaxFunction(this.parentNode)" class="folloo">Test</a>
</form>
<form name="myForm">
<input type="hidden" value="4" class="lastphp">
<a onclick="ajaxFunction(this.parentNode)" class="folloo">Test</a>
</form>
And haddle it like this
function ajaxFunction(form) {
var lastphp = form.getElementsByClassName("lastphp")[0].value;
alert(lastphp);
}
This can be alot easier with a framework, like jQuery.

Related

Ruby mechanize - discriminate two forms with their content

I have two forms with the same action, and submit button text. Only the text inside changes
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textA</h2>
</form>
</li>
<li>
<form name="login" method="post" action="">
<input name="returnURL" value="/cap/dashboard/home" type="hidden">
<input name="destURL" value="" type="hidden">
<button name="login" type="submit" class="btn-primary">
<span aria-hidden="true">Continuer</span>
</button>
<h2>textB</h2>
</form>
</li>
How can I submit the right form ?
You can use form_node to search for css/xpath:
page.forms.find{|f| f.form_node.at('h2:contains("textB")')}
It wouldn't matter though, in your example both forms do the same thing.

Select/Option Laravel 5.3

I want to use select and option in laravel 5.3 in simple HTML form. How to use select and option in laravel 5.3 in HTML form?
My coding:
#extends('layout.navigation')
<html>
<head>
</script>
</head>
<div class="row" id="contact_form">
<div class="col-sm-4">
<form action="{{route('online_form')}}" method="post" enctype="multipart/form-data">
{!!csrf_field()!!}
<br/><br/>
<div class="panel panel-default" id="form_panel">
<div class="panel-body">
<p>fill the form </p>
<input type="text" name="username" class="form-control" placeholder="Name" required>
<br/>
<input type="text" name="email" class="form-control" placeholder="Email" required><br/>
<p style="margin-top:20px;font-size:14px">Gender :&nbsp&nbsp&nbsp&nbsp <label
class="radio-inline"><input type="radio" style="margin-top:1px" name="gender"
value="Male">Male</label>
<label class="radio-inline"><input type="radio" style="margin-top:1px"
name="gender" value="female">Female<br/></label>
<p style="margin-top:20px;font-size:14px"> Select Language
:&nbsp&nbsp&nbsp&nbsp<label class="checkbox-inline"><input type="checkbox"
name="language" value="english">English</label>
<label class="checkbox-inline"><input type="checkbox" name="language"
value="hindi">Hindi</label>
<br/><br/>
<select id="state">
<option value="rajasthan">Rajasthan</option>
<option value="madhya pradesh">Madhya Pradesh</option>
</select>
<input type="submit" name="submit" value="Enter" class="btn btn-primary" >
</form>
</div>
</div>
To get the state value in the controller method, you can use Input facade.
$state = Input::get('state');
You can include the following as a dependency in composer "laravelcollective/html": "~5.0" and then include it in your config/app
Now, you can create your select dropdown using:
echo Form::select('gender', array('Male', 'Female'));
echo Form::select('language', array('English', 'Hindi'));
and so on.
For more information on this collective,
check this out.

CasperJs, how to fill a form that only have a class, not a name and not an id?

I want to fill this form, but i dont know how to do it since it only have a classname.
All the examples i saw have an id or a name, to fill the form and submit it, please help.
<form class="header_form" method="post" action="">
<div class="lgn-items">
<div class="login_item">
<label>Email</label>
<input type="text" name="email" tabindex="1" class="inputtext" id="email" />
</div>
<div class="login_item" >
<label>Password</label>
<input type="password" name="password" tabindex="2" class="inputtext" id="pass" />
</div>
<div class="lgn-add">
Registration <span>|</span>
Forgot your password ?
<div class="rembo">
<input type="checkbox" name="remember" value="1" /> Remember me
</div>
</div>
</div>
<div class="login_item lgn-btn" >
<input type="submit" name="login_button" value="Login" tabindex="3" class="login" />
</div>
</form>
You can access to your form using any selector. In your case you to it like this.
casper.then(function () {
casper.fill('form.header_form', {
/** Your parameters here **/
}, true);
});

Submitting form action using javascript codeigniter

i have error for submitting form using javascript. the error said unknown column array. what is wrong with my array or maybe on my javascript.
this is my sample code.
<form action="">
<input type="text" name="name">
<input type="text" name="age">
<input type="button"onClick="this.form.action='<?php echo site_url('core')?>/'+'add_name';this.form.submit();" value="new"/>
</form>
WORKING WITHOUT JS
Try this:
<?php
$frmAttrs = array("id"=>"addFrm");
echo form_open('core/add_name', $frmAttrs);
?>
<input type="text" name="name">
<input type="text" name="age">
<!-- <input type="button" onClick="this.form.action='<?php //echo site_url('core/')?>'+'add_name';this.form.submit();" value="new"/> -->
<input type="button" id="submitFrm" onClick="this.form.submit();" value="new" />
</form>

Editing Magento Checkout Form

On clicking "place order" in Magento, I want to capture some of its values and feed them to the following form:
<form method="post" action="https://www.jambopay.com/JPExpress.aspx" target="_blank">
<input type="hidden" name="jp_item_type" value="cart"/>
<input type="hidden" name="jp_item_name" value="test shop"/>
<input type="hidden" name="order_id" value="455879"/>
<input type="hidden" name="jp_business" value="business#yourdomain.com"/>
<input type="hidden" name="jp_amount_1" value="51"/>
<input type="hidden" name="jp_amount_2" value="0"/>
<input type="hidden" name="jp_amount_5" value="0"/>
<input type="hidden" name="jp_payee" value="email#yourcustomer.com"/>
<input type="hidden" name="jp_shipping" value="company name"/>
<input type="hidden" name="jp_rurl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=0"/>
<input type="hidden" name="jp_furl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=1"/>
<input type="hidden" name="jp_curl" value="http://www.yourwebsite.com/testpost/Result.aspx?ii=2"/>
<input type="image" src="https://www.jambopay.com/jambohelp/jambo/rsc/paymentsbyJamboPay.jpg"/>
</form>
The values include:
Order Number,
Total Amount,
Customers Email Address,
How do i do this?
You can get value of order after save order is called you can get last order id from this methods
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
once you have order id then load order like this
$order = Mage::getModel('sales/order')->load($orderId);
and you can get all details of order

Resources