views:

61

answers:

3

Hello,

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!

+3  A: 

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.

Marc B
+2  A: 

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>
captaintokyo
+1  A: 

You can use jQuery to set it to an input:

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