Jump to content

Recommended Posts

I am using dropdown box to select years and with submit button get ajax request for selected years. Following code is not working (works when page reload and server request method is post):

 

<input type='button' class='inputButton' onclick='requestActivities2(\"includes/get_monthly.php?year=\"+document.getElementById(\"yearsid\").value\"+&month=$month\");'  value='$lang[submit]' name='Submit' />

 

And select:

<select id='yearsid' name='years'>

 

How to getElementById for Ajax request with button (not submit)?

Link to comment
https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/
Share on other sites

I don't know about anything else all i can tell you is that you have conflicting "" and '' in your first line i think :/.

 

Also try.

onsubmit = "return false"

This will stop it from submitting ,and therefor, act like a button. The onclick will still do what it's supposed to do.

Not sure I understand what you're asking..? You can return the element object for a button input just like a submit input?

 

If I choose 2010 from dropdown (select) I want to get that value for Ajax request without page refreshing. So atribute onclick will be:

 

onclick='requestActivities2("includes/get_monthly.php?year=2010");'

 

requestActivities2 is Ajax script to get request from specified url.

Is this possible?

It won't work. Here is all code:

<form name='myform' method='post' action=''>

<select id='yearID' name='years'>
<option  value='2010'>2010</option>
<option  value='2009'>2009</option>
<option  value='2008'>2008</option>
</select>

<input type='button' onclick='requestActivities2("includes/get_monthly.php?year="+this.value);'  value='Submit' />

</form>

 

EDIT:

Solved:

onclick='requestActivities2("includes/get_monthly.php?year="+yearID.value); :D

Ah sorry. Okay give this a try..

 

<form name='myform' method='post' action=''>

<select id='yearID' name='years'>
<option  value='2010'>2010</option>
<option  value='2009'>2009</option>
<option  value='2008'>2008</option>
</select>

<input type='button' onclick='requestActivities2("includes/get_monthly.php?year="+document.getElementById("yearID").value);'  value='Submit' />

</form>

 

I'd definitely recommend moving such logic to a function though.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.