Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with javascript

Status
Not open for further replies.

nawrioj

Programmer
Feb 14, 2005
22
US
i got a little bit of problem with my script for php page that I'm creating. I want to assign a case with multiple practice areas which will correspond with several subpractice_areas.

I want the page to show the subpractice areas for the practice areas selected. However it is not doing anything. It did print "I'm in" but it didn't give me the subpractice areas.

Is my javascript right ? I'm new to javascript and need lots of pointers from experts.

here is my code

<script language="JavaScript" type="text/javascript">
function selectSubPrac()
{
var oForm = document.form1;
if (oForm.case_practicearea.value > 0)
{
document.write("I'm in");
oForm.isSubmitAction.value="selectSubpractice";
oForm.submit();
}
}
</script>

while ( list($practiceid, $practicename) = mysql_fetch_array($sql) )
{
echo "test";
db_connect();
$sql_2 = @mysql_query("SELECT subpractice_id, subpractice_name
FROM subpractice_area
WHERE subpractice_id = '" . $practice_id . "' ");
$javascript_block = 'javascript_block_' . $practiceid ;
$javascript_block .= '<select name="case_subpracticearea" multiple = "yes" >';
while (list ($subpracid, $subpracname) = @mysql_fetch_array($sql_2))
{
echo "subpracid = " . $subpracid;
$javascript_block .= '<option value="'.$subpracid.'>'.$subpracname.'</option>';
}
$javascript_block .= '</select>';

// populating the display block
$display_block .= "\n<tr>"
."\n<td>
\n\t<INPUT type=\"checkbox\" name=\" case_practicearea \" value=\" " . $practiceid . " \" onClick=\"selectSubPrac();\"> " . $practicename
."\n</td>";
if ($_POST[isSubmitAction] == "selectSubpractice")
{
echo "test submit";
$display_block .= "\n" . '<td>' . $javascript_block . '</td>';
}
$display_block .= "</tr>";
}



Thanks

joey
 
The javascript you wrote may well delete everything on your page before attempting to submit. The document.write() statement used on a page that's completely written will delete the contents of the page.

If you want to see a message box, use alert("Your message"); instead.

Also, do you want oForm.case_practicearea.value to only have a length greater than zero, or have a value greater than "0"? Element values are strings, not numbers, so you'd have to convert the value if that's what you want. You should check to make sure the value is a number, too, like with:
Code:
if(!isNaN(oForm.case_practicearea.value) && (oForm.case_practicearea.value * 1) > 0)
  {   
  alert("I'm in");
  oForm.isSubmitAction.value="selectSubpractice";   
  oForm.submit();  
  }

Lee
 
The value of the practicearea is numeric(IDs)
yeah U're right. The document.write delete the whole content. Thanks for the tips.

Do you understand my coding problem ? If U are, please help me further

thanks
 
You wrote:
The value of the practicearea is numeric(IDs)

That's irrelevant to what I wrote. It doesn't matter what value you plug into a form element, you're going to get a string value out of it. Period.

Other than blowing away your whole page, I don't know what your latest problem is. Show your code, and make it the output code from the page, not the scripting source that you originally provided.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top