/    Sign up×
Community /Pin to ProfileBookmark

Can you stare at this for a bit? I need a break. (onchange not firing)

So, I’ve gone and messed something up. This onchange worked fine yesterday – don’t recall doing any changes – the same onchange works in other parts of the site – and yet I have been staring at this for over an hour trying to figure out what stupid syntax or stupid whatever error I’m making that is preventing this from firing. I’m sure it’s something simple and I’m just looking too hard…

Here is the html for the relevant parts of the form:

[CODE]
<form enctype=”multipart/form-data” action=”<?php echo $_SERVER[PHP_SELF];?>” method=”POST”>

<select name=”maincat_id” onchange=”reload(this.form)”>
<option value=”0″>Select Main Category</option>
<option value=”4″>Employment</option>
<option value=”6″>For Rent</option>
<option value=”5″>Garage/Yard/Estate Sales</option>
<option value=”1″>Housing/Property</option>
<option value=”2″>Items For Sale</option>
<option value=”3″>Services</option>
<option value=”7″>Wanted</option></select>

<input type=”submit” name=”submit_ad” id=”submit_ad” value=”Submit Ad” />

</form>
[/CODE]

Here’s ALL of the javascript in the header – no other JS on the page.

[CODE]
<SCRIPT language=”JavaScript”>

function reload(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
self.location=’submitad.php?maincat_id=’ + val ;
}

function reload2(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
var val2=form.subcat1_id.options[form.subcat1_id.options.selectedIndex].value;
self.location=’submitad.php?maincat_id=’ + val + ‘&subcat1_id=’ + val2 ;
}

function reload3(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
var val2=<?php echo $_GET[ad_id];?>;
self.location=’edit.php?&ad_id=’ + val2 + ‘&maincat_id=’ + val ;
}

function reload4(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
var val2=form.subcat1_id.options[form.subcat1_id.options.selectedIndex].value;
var val3=<?php echo $_GET[ad_id];?>;
self.location=’edit.php?&ad_id=’ + val3 + ‘&maincat_id=’ + val + ‘&subcat1_id=’ + val2 ;
}

function reload5(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
var val2=<?php echo $_GET[ad_id];?>;
self.location=’ads.php?&submit=TRUE&ad_id=’ + val2 + ‘&operation=edit&maincat_id=’ + val ;
}

function reload6(form){
var val=form.maincat_id.options[form.maincat_id.options.selectedIndex].value;
var val2=form.subcat1_id.options[form.subcat1_id.options.selectedIndex].value;
var val3=<?php echo $_GET[ad_id];?>;
self.location=’ads.php?&submit=TRUE&ad_id=’ + val3 + ‘&operation=edit&maincat_id=’ + val + ‘&subcat1_id=’ + val2 ;
}

</script>

[/CODE]

What it’s supposed to do: changing selection on first <select> populates values for second <select>.

What it does: Changing the selection in the select box does nothing – doesn’t even try to reload the page.

I can give you the rest of the code if you want it, but since the onchange doesn’t even TRY to reload the page, I’m not sure it’s relevant.

This particular <select> box calls function: reload(form). I have the same <select> box on other pages of the site (where you edit all the information input on THIS page) calling reload2(form) and so on… and it works fine.

So I’m hoping someone can give me some debug ideas: “Did you check this?” “Did you forget this?” etc.. Obvious stuff that has escaped me today.

Browser: Doesn’t work in FF or IE7
link: [url]http://www.centexconnect.com/test/actions/submitad.php[/url] – here’s a test account: login: [email][email protected][/email]/ password: test

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscJun 02.2009 — There's an error in your JS code preventing any of it from working. It's because $_GET[ad_id] is giving a blank value and you then have several lines of:

<i>
</i>var val# = ; //# can be 2 or 3 in functions reload3, reload4, reload5, and reload6


in your code.

Firebug is a fantastic add on for firefox that debugs javascript code, among other things
Copy linkTweet thisAlerts:
@SummerSongauthorJun 02.2009 — You are my new best friend ? Thanks so much for your help...I hate staring at code having no idea what to try next.
×

Success!

Help @SummerSong spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...