PDA

Click to See Complete Forum and Search --> : forms/ send user 2 new htm page


pnj
Oct 11th, 2000, 04:03 PM
hello,
I am making a form and I need two things to happen.
one is call a javacript function and the other
is send the user to another page.

the javacript works but it won't call the other page.

+++++++++++++++++++++++++++++
<form action="test1.html" name=Myform>
<input type="text" name="something">
<input type="button" value="submit" onClick="AddNameParts();">
</form>

+++++++++++++++++++++++++++++
AddNameParts is the Javascript function I am calling.that part works.

if I change the input type to submit instead of button then
it goes to test.html but the javascript part works.

any suggestions as to what I am doing wrong?

thanks

RealisticGraphics
Oct 11th, 2000, 07:06 PM
I'd just do this


<script>
function AddNameParts(){
//Add your code for whatever happens here
//then add the following before you end the function:

location.href = "test1.html"
}
</script>
<form name=Myform>
<input type="text" name="something">
<input type="button" value="submit" onClick="AddNameParts()">
</form>

This way whenever your function is finished, it takes them to test1.html. If you need anything else, please let me know.

pnj
Oct 14th, 2000, 01:31 AM
here is my code:
____________________________________
<script language="javascript">

function valid()
{
if (theForm.fname.value !="")
location.href=test.html;
else{
alert("enter some ****");
return false;
}
}
</script>
</head>
<body>

<form name="theForm" onSubmit="valid();" method=post>
<input type=text name="fname">
<input type=submit value=enter>
</form>
________________________________________

I get an error message that says test is undefined


thanks for your help

RealisticGraphics
Oct 14th, 2000, 08:59 AM
Try using this code... You missed some brackets and also, javascript tends not to like the "Submit" ability of forms when you're using it to leave the page because it'll do activate a "Refresh" on the current page canceling out your code. There are ways around it, but I couldn't tell you what they are. Make your code look like the following and it should work:


<script language="javascript">

function valid()
{
if (theForm.fname.value != ""){
location.href="test.html";}
else{
alert("enter some ****");
return false;
}
}
</script>
</head>
<body>

<form name="theForm">
<input type=text name="fname">
<input type=button value=enter onClick="valid()">
</form>

pnj
Oct 14th, 2000, 10:51 AM
thanks for the reply.
it works now but only in IE.in Netscape I get an error that says: theForm not definded
I don't get it.

thanks again.

pnj
Oct 14th, 2000, 10:56 AM
opps....
I just put in:
document.theForm.fname.value
and now it works.
i guess netscape needs the document part.
+++++++++++++++++++++++++++++++++++++++++

now i would like to parse the string that is put in and capitolize the first letter, so pizza would become Pizza.
I need to use an array that is the size of fname.length.
and then use charAt(). but I do not know the correct syntax.

any suggestion on that one?
thanks again RealisticGraphics.

RealisticGraphics
Oct 14th, 2000, 09:30 PM
Glad I can help :) And yes, you're right, you must use a "document" so that Netscape knows what you're talking about. As for your next question, I think this should get you what you need.


<script language="javascript">
var tArray = new Array();
var NewString
var i
var z

function valid()
{
tFname = document.theForm.fname.value
tLength = tFname.length
if (document.theForm.fname.value != ""){
for(i=0; i < tLength; i++){
tArray[i] = tFname.charAt(i)}

for(z=0; z < tArray.length; z++){
if(z == 0){NewString = tArray[0].toUpperCase()}
else{NewString = NewString + tArray[z]}}
alert(NewString)}
else{
alert("enter some ****");
return false;
}
}
</script>
</head>
<body>

<form name="theForm">
<input type=text name="fname">
<input type=button value=enter onClick="valid()">
</form>
</body>


Let me know if you need anything else.