Results 1 to 2 of 2

Thread: including external js script

  1. #1
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default including external js script

    hi

    i dont know if this is the best way of doing this but this works locally

    what im trying to do is make 2 drop down boxes, one with make and one with model (cars) when the make is changed the model drop down is updated... i could do this easy peasy but i dont wanna refresh the page.

    heres what i have and it works perfectly locally in ie6 (not tested in any other browser yet) but i upload all the files (.html/.js) and it doesnt work properly...

    Code:
    <script language="javascript">
    function seconddrop(selected)
    {
    	for(i=0;i<document.forms['filter'].model.options.length;i++) {
    		document.forms['filter'].model.options.length=1;
    	}
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', selected+'.js');
        html_doc.appendChild(js);
        return false;
    
    }
    </script>
    
    <form id="filter" method="POST" action="">
    	<p>
    	<select size="1" name="make" ONCHANGE="seconddrop(this.value);">
    	<option selected value="CHOOSE">CHOOSE</option>
    	<option value="Fiat">Fiat</option>
    	<option value="Ford">Ford</option>
    	</select>
    	<select size="1" name="model">
    	<option selected>CHOOSE</option>
    	<option>bob</option>
    	<option>bob2</option>
    	</select>
    	</p>
    </form>
    the js im including looks like this

    Code:
    document.forms['filter'].model.options[1] = new Option('FORD1','FORD1');
    document.forms['filter'].model.options[2] = new Option('FORD2','FORD2');
    document.forms['filter'].model.options[3] = new Option('FORD3','FORD3');
    document.forms['filter'].model.options[4] = new Option('FORD4','FORD4');
    i have no idea where the script is failing online but i know its getting past the for loop because the second dropdown box options are getting cleared

    ive tried searching google but tbh i havnt a clue if im searching for the right things. i dont know all that much about js. also ive made this script out of bits ive found online so i could be doing it completly wrong.

    thanks for any help.

  2. #2
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok sorry ive now fixed this

    not sure wether it was the fact that my dropdown value was Ford instead of ford or wether it was a permission thing beause i changed both of them and now it seems to be working...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •