Tuesday, May 24, 2011

Re: jquery onchange select go to another webpage

You're really getting the input function to print out an onchange
event in the HTML, which calls the js when the page is viewed.
Everything has to start in the PHP :)

On May 23, 10:11 am, arron <w...@wwisinc.com> wrote:
> Thank you for your help it works now.
>
> <script type="text/javascript">
> function jumpMenu(div) {
> //get value of select menu
>
> //added the url parameter so it routers correctly
> var url=("view/");
> var newLocation = $(div).val();
>
> //added url var so it goes to the right page
>
> location.href = (url+newLocation);
>
> }
>
> </script>
> <div class="jumpMenu">
> <?php echo $this->Form->create('state');?>
> <fieldset>
> <legend>
> <?php
> echo $this->Form->input('State.state_id', array('onchange' =>
> 'jumpMenu(this);'));
> ?>
> </fieldset>
> <?php echo $this->Form->end('Submit');?>
> </div>
>
> I just have a hard time figuring out when i need to use php to call js
> if that makes sense
>
> On May 20, 6:29 pm, Richard Garand <richard.gar...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hello Arron,
>
> > The first thing you'll want is an onchange event for the select
> > created by $this->Form->input; you should be able to do it like so:
>
> > echo $this->Form->input('State.state_id', array('onchange' =>
> > 'jumpMenu(this);'));
>
> > This will pass the select DOM element to the javascript function, so
> > you would then need to change it to use $(div).val().
>
> > Richard
>
> > On May 20, 1:51 pm, arron <w...@wwisinc.com> wrote:
>
> > > Hi everyone im kinda new to cake. I have a silly problem.
>
> > > I have a database composed of states. What i'm trying to do is when
> > > you click the select box it goes to the detail page of the state you
> > > have chosen.
>
> > > I cant figure out how to do a jquery onchange jump to the state id.
>
> > > I have always done this threw Dreamweaver and have never had to do
> > > this in cake.
>
> > > //controller
>
> > > function xindex() {
>
> > > $this->set('states',$this->State->find('list'));
>
> > > }
>
> > > //view
>
> > > <script type="text/javascript">
>
> > > function jumpMenu(div) {
>
> > > //get value of select menu
>
> > > var newLocation = $("#"+div).val();
>
> > > location.href = newLocation;
>
> > > }
>
> > > </script>
>
> > > <div class="examples form">
>
> > > <?php echo $this->Form->create('state');?>
>
> > > <fieldset>
>
> > > <legend>
> > > <?php
>
> > > echo $this->Form->input('State.state_id');
>
> > > ?>
>
> > > </fieldset>
>
> > > <?php echo $this->Form->end('Submit');?>

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: