fanfavorite Posted June 24, 2008 Share Posted June 24, 2008 I have a form that is setup like so: <form enctype="multipart/form-data" id="orderform" name="orderform" action="page1.php" method="post"> <select name="website" onchange="showField(this.value,'havesite2','null','null')"> <option value="No"<? if ($_POST['website'] == "No") { echo ' selected="selected"'; } ?>>No</option> <option value="Yes"<? if ($_POST['website'] == "Yes") { echo ' selected="selected"'; } ?>>Yes</option> </select> <div id="havesite2"></div> </form> Now showField updates the havesite2 div. If you pick yes this is in havesite2 div: <script type="text/javascript"> <!--// document.getElementById('orderform').action = "page2.php"; //--> </script> If you pick no this is in havesite2 div: <script type="text/javascript"> <!--// document.getElementById('orderform').action = "page1.php"; //--> </script> I have also tried: document.orderform.action = "page2.php"; But nothing seems to work. Any ideas why? Thanks, -JC EDIT: Just wanted to also mention that the AJAX is actually updating the havesite2 div correctly. I use firebug in firefox to check. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 24, 2008 Share Posted June 24, 2008 It worked fine for me. Are you sure the code for showField() is working properly? Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks for the reply. Yeah I am sure that showField is working as I insert more than just that when changed. Instead of putting it in the div, I just rewrote the code to include it in the showField and it works now: if (value == "Yes" && div1 == "havesite2") { document.getElementById('orderform').action = "page2.php"; } else if (value == "No" && div1 == "havesite2") { document.getElementById('orderform').action = "page1.php"; } Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 Well it is working fine in Firefox, but Internet Explorer gives the following code: "Object doesn't support this property or method" IE7 doesn't like: document.getElementById('orderform').action = "page2.php"; and document.getElementById('orderform').action = "page1.php"; Any ideas? Could it be because this is in a separate js file? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 The separate JS file doesn't matter. You aren't calling that code until after the page loads right? I just tested this in IE7 and it worked fine: <html> <head> <script type="text/javascript"> window.onload = function ( ) { document.getElementById('orderform').action = "page2.php"; } </script> </head> <body> <form enctype="multipart/form-data" id="orderform" name="orderform" action="page1.php" method="post"> <input type="submit" /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 Still have no idea why IE7 has the problem. Here is more of the code. I stripped a lot out for easy reading. ajax.js: function showField(value,div1,post1,post2,post3,post4) { if (value == "Yes" && div1 == "havesite2") { document.getElementById('orderform').action = "page2.php"; } else if (value == "No" && div1 == "havesite2") { document.getElementById('orderform').action = "page1.php"; } xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="change.php"; url=url+"?value="+value; url=url+"&div1="+div1; url=url+"&post1="+post1; url=url+"&post2="+post2; url=url+"&post3="+post3; url=url+"&post4="+post4; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=function () { stateChange(div1); }; xmlHttp.open("GET",url,true); xmlHttp.send(null); } index.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>TESTING</title> <script type="text/javascript" src="js/ajax.js"></script> </head> <body> <form enctype="multipart/form-data" id="orderform" name="orderform" action="page1.php" method="post"> <select name="website" onchange="showField(this.value,'havesite2','','','','')"> <option value="No"<? if ($_POST['website'] == "No") { echo ' selected="selected"'; } ?>>No</option> <option value="Yes"<? if ($_POST['website'] == "Yes") { echo ' selected="selected"'; } ?>>Yes</option> </select> <script type="text/javascript"> <!-- showField('$_POST[website]','havesite2','','','',''); --> </script> </div> <div id="havesite2"></div> <input type="submit" alt="Submit" name="submit" id="submit" value=" " class="formsubmit" /></div> </form> </body> </html> If I comment out the document.getElementById('orderform').action = "page2.php"; and document.getElementById('orderform').action = "page1.php"; then the script works fine other than not changing the action obviously, but no errors. Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 hmmm, I just tried this and it works. Going to have to do more looking into. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 yeah...i was just about to say...works for me (except for the AJAX part cus I don't have your code for GetXmlHttpObject() ...if it is the AJAX part, I recommend saving yourself the trouble and just using a JS library to do that work for you. jQuery is my favorite, but prototype and Dojo are two others that work. once you use them, you will discover how much easier javascript becomes. instead of worrying about making it work in every browser, you worry about the actual logic in your code. Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 Oh man, what a headache. I had a hidden field with the name "action", which was causing a problem with IE. I didn't even need this hidden field anymore and just overlooked it. After I removed this, everything is fine. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 yup...that'll do it Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 I haven't really looked into JS libraries or anything yet, maybe I should start reading up on it. Quote Link to comment 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.