Radio button selection javascript validation--kinda
I barely understand the requirements myself, so if the question seems incoherent, it probably is.
I have a php-based web site that has a form with seven radio buttons, each next to a "task name" (right now this is strictly in demo mode, so the task itself is immaterial and I don't even know if it will be a file that opens, a form needs to be filled out or some other kind of task) and five icons. When a task is selected and an icon is clicked upon, a new page is supposed to open and display the task name and the icon name.
Now the form never really is submitted anywhere, it's mostly a method of displaying and selecting a task. The clicking on the icon is supposed to trigger the new page opening.
My problem is twofold. First, if no of the task has been selected, I need to disable the icon trigger. Second, once a task as been selected and an icon clicked, I can't seem to capture the task name in any way so I can pass it to the new page.
Here is the javascript I've attempted to write to get the selected task. I've littered a few alert prompts to let me know where in the script it gets to, but none get triggered.
<script type="text/javascript">
function getValue(form) {
alert ("HELLO");
for (var i = 0; i < form.task.length; i++) {
alert(form.task.length);
if (form.task[i].checked) {
break;
}
}
var Result = form.task[i].value;
alert ("My function is: " + Result + ".");
location.href="task.php?Result=" + Result +"&username=$username&function=this"; //This causes the browser to go to admin2.php
</script>
Here's the form info:
<form name="tasks" id="task" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="task" id="wssg" value="Water-Soluable Super-Glue" onChange="getValue(this.form)" /><span class="list"><label for="wssg">Water-Soluable Super-Glue</label></span><br />
<input type="radio" name="task" id="bs" value="Biodegradable Styrofoam" onChange="getValue(this.form)" /><span class="list"><label for="bs">Biodegradable Styrofoam</label></span><br />
<input type="radio" name="task" id="mpv" value="Magnet-Powered Vacuum" onChange="getValue(this.form)" /><span class="list"><label for="mpv">Magnet-Powered Vacuum</label></span><br />
The onChange event of the task isn't triggered at all. I'm stumped and I have to turn this in by tomorrow morning.
Any assistance would be greatly appreciated.
Dami posted this at 13:43 — 24th September 2010.
She has: 88 posts
Joined: Sep 2001
In rereading the original post, I can see how this might have appeared to be for a homework assignment. It wasn't. It was for a job proposal.
I'm still curious how it would be done, even though the proposal deadline is over.
TIA.
jennywong posted this at 09:37 — 25th September 2010.
They have: 2 posts
Joined: Sep 2010
you can take it to your friend who is fit for it.
Dami posted this at 13:02 — 25th September 2010.
She has: 88 posts
Joined: Sep 2001
Sorry, I don't understand your response.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.