Deoctor Posted January 11, 2012 Share Posted January 11, 2012 hai i am new to javascript so please try to bare with me. i have a code which does the job of changing the value show at the bottom of select box dynamically. but the thing is it should actually need to change between only two values only so how can i change the script to do that <code> <html> <head> <script type="text/javascript"> myarr=new Array() myarr[401] = "Local path " myarr[403] = "URL or Local path " myarr[404] = "URL or Local path " myarr[405] = "URL or Local path " myarr[406] = "URL or Local path " myarr[407] = "URL or Local path " myarr[408] = "URL or Local path " myarr[409] = "URL or Local path " myarr[410] = "URL or Local path " myarr[411] = "URL or Local path " myarr[412] = "URL or Local path " myarr[413] = "URL or Local path " myarr[414] = "URL or Local path " myarr[415] = "URL or Local path " myarr[500] = "URL or Local path " myarr[501] = "URL or Local path " myarr[502] = "URL or Local path " myarr[503] = "URL or Local path " myarr[504] = "URL or Local path " myarr[505] = "URL or Local path " function doIt(objval) { document.getElementById("msg").firstChild.nodeValue=myarr[objval]; } </script> </head> <body> <form name="myform"> <select name="code" onChange="doIt(this.options[this.selectedIndex].value)"> <option value="401">401 Authorization Required</option> <option value="403">403 Forbidden</option> <option value="404">404 Not Found</option> <option value="405">405 Method Not Allowed</option> <option value="406">406 Not Acceptable (encoding)</option> <option value="407">407 Proxy Authentication Required</option> <option value="408">408 Request Timed Out</option> <option value="409">409 Conflicting Request</option> <option value="410">410 Gone</option> <option value="411">411 Content Length Required</option> <option value="412">412 Precondition Failed</option> <option value="413">413 Request Entity Too Long</option> <option value="414">414 Request URI Too Long</option> <option value="415">415 Unsupported Media Type</option> <option value="500">500 Internal Server Error</option> <option value="501">501 Not Implemented</option> <option value="502">502 Bad Gateway</option> <option value="503">503 Service Unavailable</option> <option value="504">504 Gateway Timeout</option> <option value="505">505 HTTP Version Not Supported</option> </select> <!--<span id="msg">Keyword</span>--> <label style="display:block;margin-top:0.5em" id="msg">Local path <input type="text" size="30" name="path" id="path" /></label> </form> </body> </html> </code> Quote Link to comment https://forums.phpfreaks.com/topic/254789-dynamically-change-text-based-on-dropdown-selection/ Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 The description of your issue isn't exactly helpful I'm afraid. Quote Link to comment https://forums.phpfreaks.com/topic/254789-dynamically-change-text-based-on-dropdown-selection/#findComment-1306414 Share on other sites More sharing options...
Deoctor Posted January 11, 2012 Author Share Posted January 11, 2012 oops. Sorry that i could not be more specific ,thank you for your reply any way I have resolved it. What i wanted was instead of repeating the same value in the array for all others i wanted something like for 401 it should show one value where as for others it should show other values for this to achieve this small change in the code need to be done <script type="text/javascript"> function doIt(objval) { document.getElementById("msg").firstChild.nodeValue= (objval === "401") ? 'Local path' : 'URL or Local path '; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/254789-dynamically-change-text-based-on-dropdown-selection/#findComment-1306438 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.