/    Sign up×
Community /Pin to ProfileBookmark

Parameter Values from Javascript dont transfer to my controller

Hello, I’m currently doing development using a controller and also doing some frontend work with javascript. When I say controller, i refer to something used in Apache’s Catalyst framework, which is based on the MVC architecture.

Basically I am trying to create adjacent drop down menus, Menu1 and Menu2.

If I select something in Menu1, Menu2 will be populated accordingly.

Since in my case, Menu1 was a short list, I hardcoded the list in HTML (yes not so smart). However, Menu2 uses a javascript to have it populated.
HTML excerpt:

[code=html]
<form action=”add_action.html” name=”cat_form”>

<select name=’first_category’ class=”input” onChange=”secondDisplay()”>
<option value=”>(Select a Category)</option>
…(categories hardcoded here)
</select>
</td>
<td id=”second_category_td”>
<select name=’second_category’ class=’input’>
<option value=’0′>(Select a Category)</option>
</select>
</td>
</tr>

<tr class=’main’ valign=’top’>
<td>&nbsp;</td>
<td><br><input type=’submit’ name=’s’ value=”save” id=”save” class=’button’></td>
</tr>
</table>
</form>
[/code]

javascript:

[CODE]function secondDisplay(){
var td = document.getElementById(‘second_category_td’);
var select = “<select class=’input’ name=’second_category’ >n”;
var i;
select = select.concat(“<option value=’0′>(Select a Category)</option>n”);
for (i = 0; i < catArray.length; i++) {
if(catArray[i].parent_category_id == document.[%form_name%].first_category.value) {
select = select.concat(“<option value='” + catArray[i].category_id + “‘>” + catArray[i].name + “</option>n”);

}
}
select = select.concat(“</select>n”);
td.innerHTML = select;
}[/CODE]


—————————–

Here’s my problem… “second_category” doesn’t pass on to my controller and only “first_category” does, although it shows up perfectly on the webpage… anyone know why? And thanks in advance!

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — ... doesn't pass on to my controller...[/QUOTE]
Just what does that mean? Also... Are there FORM tags in this document? Where are they?
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — Just what does that mean? Also... Are there FORM tags in this document? Where are they?[/QUOTE]

Thanks for the quick feedback. Sorry for lack of info, please feel free to keep asking.

Controller: it's what controls the logic of all my webpages and tells it where to go and how to process the form data (like java struts i think). I typically access the parameters like $c->params->{"first_category"} in mod_perl. I pasted the form tag at the top. Let me know if you need more info again. Thanks.

Keep in mind the add_action.html does nothing, it's blank. my controller, a mod_perl file, is triggered when add_action.html is executed and is supposed to handle things from there.

[%form_name%] is using template toolkit and is correctly populated with the "CAT_FORM" string.
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — ...and where is the closing FORM tag?
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — ...and where is the closing FORM tag?[/QUOTE]

updated, thanks. and i forgot to mention that the javascript and html portion are all in one HTML file, called "add.html"
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — You don't show the start of the TABLE. Is it directly after the opening FORM tag? Presuming so...

Are you saying that when this form is submitted, that the second SELECT element's value is not submitted to the server? How do you know this for certain?
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — You don't show the start of the TABLE. Is it directly after the opening FORM tag? Presuming so...

Are you saying that when this form is submitted, that the second SELECT element's value is not submitted to the server? How do you know this for certain?[/QUOTE]


sorry, i am pretty certain the tags are correctly placed, i just dont want to overwhelm others with a bunch of html code. and yes you are absolutely correct. the "second_category" parameter and associated value is not passed to the server. I know this for certain because i was doing some debugging work:

Below is a rough snippet of the controller code that is supposed to handle the form action. It's a function/subroutine called 'add' that is triggered when 'add_action.html' is submitted. in the body im just showing an example of the debugging i did.
[CODE]
sub add_action::("add_action.html") {
$args = $req->params(); //get parameters passed onto the server
//foreach loop prints out all the parameters passed from the webpage to the server
//i inspected all the parameters, and only 'first_category' was printed.
foreach my $key ( keys %$args ) {
print "$key n";
}
}[/CODE]
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — If you'd like to experiment with me, change your form tag as follows and give me a link to try your page live on the Internet. I have some client-side tools with which I'd like to examine your page in action.

<form method="get" action="add.html" name="cat_form">
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — [%form_name%] is using template toolkit and is correctly populated with the "CAT_FORM" string.[/QUOTE]
By the way... I hope the above statement is a typo. Your form tag NAME attribute's value does not match what you typed above.
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — hey i'll try that out, but i cant let you view the page or at least i dont know how because vpn access is needed. i'll let you know what my findings are. but i have to go home now so i'll be back later. THanks for your help.
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — http://localhost/.../add.html?name=&amp;first_category=2&amp;description=&amp;action_url=&amp;action_description=&amp;s=save

so i guess that confirms it :-(

i dont know why second_category is like a ghost...
Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — hehehe, I do have VPN capability on my computer -- with which I can connect to my client's systems. But, I suppose if I get to that level I would have to charge you as I do my other clients. ? As somebody else on this forum says in their signature line, "If you PM me, you pay me. The forum is for free."
Copy linkTweet thisAlerts:
@newbieguyauthorMar 04.2006 — ah but there's no fun in it when it's not free ? .

anyhow, i am thinking if my problem has to do with the td.innerHTML call. so i'm gonna do some research for a bit.
Copy linkTweet thisAlerts:
@newbieguyauthorMar 06.2006 — bump for help ? why does it not cooperate with me ?
×

Success!

Help @newbieguy 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...