|
-
Oct 11th, 2000, 04:03 PM
#1
Thread Starter
Fanatic Member
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
-
Oct 11th, 2000, 07:06 PM
#2
Fanatic Member
I'd just do this
Code:
<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.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Oct 14th, 2000, 01:31 AM
#3
Thread Starter
Fanatic Member
that isn't working
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
-
Oct 14th, 2000, 08:59 AM
#4
Fanatic Member
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:
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">
<input type=text name="fname">
<input type=button value=enter onClick="valid()">
</form>
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Oct 14th, 2000, 10:51 AM
#5
Thread Starter
Fanatic Member
ARRRRGG!
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.
-
Oct 14th, 2000, 10:56 AM
#6
Thread Starter
Fanatic Member
sorry......it works...
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.
-
Oct 14th, 2000, 09:30 PM
#7
Fanatic Member
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.
Code:
<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.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|