eevan79 Posted September 26, 2010 Share Posted September 26, 2010 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)? Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/ Share on other sites More sharing options...
Adam Posted September 26, 2010 Share Posted September 26, 2010 How to getElementById for Ajax request with button (not submit)? Not sure I understand what you're asking..? You can return the element object for a button input just like a submit input? Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1115959 Share on other sites More sharing options...
Omirion Posted September 26, 2010 Share Posted September 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1115985 Share on other sites More sharing options...
eevan79 Posted September 27, 2010 Author Share Posted September 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1116175 Share on other sites More sharing options...
Adam Posted September 27, 2010 Share Posted September 27, 2010 Try this: onclick='requestActivities2("includes/get_monthly.php?year="+this.value);' Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1116189 Share on other sites More sharing options...
eevan79 Posted September 27, 2010 Author Share Posted September 27, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1116193 Share on other sites More sharing options...
Adam Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/#findComment-1116195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.