I'm working on a web search form which will return images and web results when they click on the link on top of the form.
So I tried to trigger the form on a link click. Example: If they click image then am trying to submit the form with the image as an option. On the link click I am able to create the hidden input, but the submit itself is not triggered.
Without hidden input I also tried the
which is not trigerring.
<strong>HTML & FORM</strong>
jQuery
What is wrong in here?
NOTE: Am trying this in wordpress does that make any sense?
<strong>EDIT</strong> after question posted
I tried the above to make sure whether the form is submitted or not, when i click the link i'm getting the
alert message. It seems to work the submit event but it is not submitting to external url in
field as well
in action.
What is going on here? Any idea would be helpful.
So I tried to trigger the form on a link click. Example: If they click image then am trying to submit the form with the image as an option. On the link click I am able to create the hidden input, but the submit itself is not triggered.
Without hidden input I also tried the
Code:
jQuery("#web_form").submit();
<strong>HTML & FORM</strong>
Code:
<span class="web"><a href="#">Web</a></span><span class="image"><a href="#">Image</a></span>
<form method="post" id="web_form" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="submit" value="Search" name="submit"/>
<?php
if (isset($_POST['submit']))
{
$option = $_POST['searchoption'];
//perfoming statement based on option
}
?>
</form>
jQuery
Code:
jQuery(document).ready(function(){
jQuery('.web').click(function () {
var option = jQuery("<input type='hidden' name='searchoption'/>");
option.val(jQuery(this).attr("class"));
jQuery("#web_form").append(option).submit();
return false;
});
});
What is wrong in here?
NOTE: Am trying this in wordpress does that make any sense?
<strong>EDIT</strong> after question posted
Code:
jQuery(document).ready(function(){
jQuery('.web').click(function () {
var option = jQuery("<input type='hidden' name='searchoption'/>");
option.val(jQuery(this).attr("class"));
jQuery("#web_form").append(option).submit();
return false;
});
$( "#web_form" ).submit(function( event ) {
alert( "Handler for .submit() called." );
});
});
I tried the above to make sure whether the form is submitted or not, when i click the link i'm getting the
Code:
Handler for .submit() called.
Code:
action
Code:
<?php echo $_SERVER['PHP_SELF'];?>
What is going on here? Any idea would be helpful.