2

This has got me in a pickle, though I'm sure it's probably fairly easy.

I need to get the hash value from the parent window uri, and insert this into the set_value() function. Obviously I can't get a hash with PHP, so it has to be javascript.

parent.location.hash

works but I've no idea how to get it into set_value().

The following is the code I'm working with (obviously wrong but you get the idea):

<label for="appt_start">Start Time</label>
<?php echo form_error('appt_start'); ?>
<br />
<input id="appt_start" type="text" name="appt_start" maxlength="12" 
value="<?php $time = "<script>document.write('parent.location.hash');
</script>"; set_value('appt_start', $time) ;?>" />

Thanks!

1
  • Sorry for the delay, and thanks for the replies. The form is being pulled into the page via ajax (jquery) so i was having trouble with the Captain Tokyo's answer, not sure why entirely. The dark horse has won this one, Tpae (at the bottom of the answers), so thank you for that! Commented Oct 21, 2010 at 14:15

3 Answers 3

4

You'd need to use an AJAX call to send it back to the server. Javascript works on the client side, PHP works on the server. By the time the page is loaded and the client gets around to executing the Javascript, the server-side PHP has already finished its work and shut down. There's no way for the two to work together directly.

Sign up to request clarification or add additional context in comments.

Comments

3

set_value sets the value of an <input> field. This can also be done in javascript, without using Ajax or PHP.

<html>
<head>
    <script type="text/javascript">
        window.onload = set_hash_value_to_appt_start;

        function set_hash_value_to_appt_start()
        {
            appt_start = document.getElementById('appt_start');
            appt_start.value = parent.location.hash.substring(1);
        }
    </script>
</head>
<body>
    <input id="appt_start" type="text" name="appt_start" maxlength="12">
</body>
</html>

Comments

1

You can use jQuery to set it to an input:

$('#appt_start').val(parent.location.hash);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.