...

View Full Version : window.location problems



bvtoffin
07-09-2004, 03:07 AM
Hi All - have the following code which I am trying to have re-direct the user to a page (in the same window) dependant on what they enter into one of the text fields. At the same time it is ading the info from the text field to a database (not sure if this effects anything).
Just can't seem to get it to work (althought I can get it to work using window.open) ???

Can some one let me know where I am going wrong - cheers.

<script language="JavaScript">
// <!--

function page_shift(f)
{
var deal_no1 = f.elements["dealno"].value;
var deal_no = (deal_no1.substring(0,2));
var page_url = "typical.asp?id="
var page_jump = page_url + deal_no;
// alert(page_jump);
window.location = page_jump;
}

// -->
</script>


<body>

<form ACTION="<%=MM_editAction%>" name="dealsearch" method="POST" onSubmit="page_shift(this)">

<input type="text" size="3" name="dealno" maxlength="4">&nbsp;<input name="" type="submit" value="Go">

<input type="hidden" name="MM_insert" value="dealsearch">
</form>

</body>

Appreciate the help.

shlagish
07-09-2004, 03:13 AM
maybe
window.location.replace(page_jump);

bvtoffin
07-09-2004, 03:24 AM
Nope - didn't seem to work.

Thanks anyway...

glenngv
07-09-2004, 04:18 AM
You can't submit the page and redirect to a different page at the same time at the same window. You must redirect to a new window. But why not put the redirection in the MM_editAction page?

bvtoffin
07-09-2004, 04:29 AM
Hi Glenn,

I need to add the first 2 digits from the text field to the URL - ie. typical.asp?id= + the 2 digits thus giving - typical.asp?id=12.

Not sure how to add to the <%=MM_editAction%> but only take the first 2 digits (its a 4 digit field).

Cheers

glenngv
07-09-2004, 07:12 AM
You can do the string manipulation in the server-side.


dealnum = request.form("dealno")
if len(dealnum)<>4 then
'save data to database

'redirect after saving the record
response.redirect "typical.asp?id=" & mid(dealnum, 1, 2)
else
response.write "error in deal number"
end if

bvtoffin
07-12-2004, 06:50 AM
Cheers Glenn,

Have sorted it using <%=MM_editAction%> - as per your first suggestion which made me think...

Appreciated!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum