Link to home
Create AccountLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php onchange event

I have the following onchange event working in my php page:

<select name="statuscompleted[<?php echo $row_orders['ID']; ?>]" class="build" id="build[<?php echo $row_orders['ID']; ?>]" tooltipText="Select a value - the checkbox selection will be entered into the database as completed" onchange='this.form.submit();'>
                                                    <option value="Select">Select</option>
                          <option value="Completed">Completed</option>
                                                  </select>

I need the onchange event to go to a named anchor in the page after completion - any ideas ?
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Hi,

if you set the action property of your form to something like this:
<form method="post" action="mypage.html#myNamedAnchor">
...
</form>

it should work.. The submit will post to the url, including the anchor that you specified.


Best regards
Avatar of doctorbill

ASKER

Sorry - I was not specific enough.
The script above is in various locations on the page. I need the page to go back to the location from where the script was actioned
Avatar of Julian Hansen
Not clear what you are doing here.

OnChange submits the form which results in the form being posted back - are you saying that you want the data to be posted back and then regenerate the page and have it scroll to the point where the onchange happened?

Sounds like something you should probably doing through an AJAX call?

Is this a case of wanting to update something on the form based on the selection from a drop down? If so you need to look at AJAX for this.

Post back if this is what you are looking for.
ASKER CERTIFIED SOLUTION
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I will try this out asap
Head section (my form is called form1):
<script type="text/javascript">
      function GoBackTo(anchor1)
      {
            form1.action = 'orders_find_visit_print_custom_status_noforms_nocosts_idfilter2.php#' + anchor1;
            form1.submit()
      }
</script>

The onchange script:
<select name="statuscompleted[<?php echo $row_orders['ID']; ?>]" class="build" id="build[<?php echo $row_orders['ID']; ?>]" tooltipText="Select a value - the checkbox selection will be entered into the database as completed" onchange="GoBackTo(anchor1');">
                                                    <option value="Select">Select</option>
                          <option value="Completed">Completed</option>
                          </select>

Sorry - this is not working. No form submission
@doctorbill - no response on my post?

What is it you are actually trying to achieve - why are you wanting to jump to the change location after a form submit?

I repeat what I asked earlier - are you trying to update your form based on a dropdown value?
Do you get errors in the javascript part? You can visualize them in your browser. One thing I notice is that you missed an ' in your onchange event, please check if that is the problem and let me know.

onchange="GoBackTo(anchor1');" should be onchange="GoBackTo('anchor1');"
Thanks very much - solution