Forum Moderators: open

Message Too Old, No Replies

Can't change form action

..And where did that querystring come from?

         

garann

8:30 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



I've got a table of data that can be sorted one of two ways. I tried to accomplish this simply by making the column names links that resubmit the form, switching the querystring. I use a JavaScript to change the form action and submit the form. Here's that code:

<script type="text/javascript">
function reSort(flag) {
var frm = document.forms[0];
frm.action = "reportOrg.aspx?sort=" + flag;
frm.submit();
}
</script>
...
<td><a href="#" onclick="reSort('event')">Event</a></td>

ASP.NET should then look for "sort" in the querystring and store its value:


sortOrd = request.queryString("sort")
if sortOrd = "" then
sortOrd = "name"
end if

When the form is submitted normally (with its Submit button) it fills the table with data, and the values submitted stay in the form. But when I press my re-sort links, two things go wrong. First, the form is blank, even though it's full of data when the JavaScript submits it. (There's no data in the table, either.) Second, I get this weird queryString:
[example.com...]

What am I doing wrong?

txbakers

9:27 pm on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have to add sortOrd to your query in an order by clause.

I do it the same kind of way, but without javascript.

I just use a href links and include the sort code in the link.

href=thispage.asp?s=N

or

hred=thispage.asp?s=A

to sort by number or Alpha.

Then my query looks like this (in jscript):

sql = "select fields from table where conditions ";

if (Request("s") == "N" ¦¦ String(Request("s")) == "undefined") {
sql += " order by name";
} else {
sql += "order by number"
}

garann

9:56 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



I guess I'm not being clear. Getting the query ordered by whatever the sort type is works fine, but the ASP.NET script isn't getting the sort type, or the values selected in the form. When I click the link that re-sorts my data, the form has selections made and the table is populated. Once the page processes, the form and table are empty and I have the weird queryString from my first post.

Does that make sense?

<added>Oh, a little more information that may be useful: the form's method is POST, not GET, which is why the queryString from the first post is so weird - the only thing in the queryString should be "sort". Sorry I'm explaining this so badly...</added>