Solved

javascript show hide in php file

Posted on 2010-09-20
3
268 Views
Last Modified: 2012-05-10
Hi,

I am novice at both JavaScript and PHP so any help would be greatly appreciated. I am building a job posting website using Drupal. For my user application form I would like to show and hide sections of the application form.

What I require is, when a user clicks New Zealand as their country I would like to display a section with the field 'city'. When a user selects any country that is not New Zealand I would like a section to display asking the users about their eligibility to work in New Zealand.

This is the form code I have (Just no idea how to use JavaScript with it). I won't list all the countries or regions as that would be a lot of code.

Thank you very much for any help,
Dan

<?php
  $form['job_posting_country'] = array(
    '#type' => 'select',
    '#title' => t('Country'),
    '#default_value' => variable_get('feed_item_length','New Zealand'), 
    '#required' => True,
    '#options' => array(
        'New Zealand' => t('New Zealand'),
        'Australia' => t('Australia'),       
        'Afghanistan' => t('Afghanistan'),
        'Albania' => t('Albania'),
        'Algeria' => t('Algeria'),
         ),
        '#description' => t('Select the country you currently live in'),
);

$form['job_posting_region'] = array( 
    '#type' => 'select',
    '#title' => t('Region'),
    '#default_value' => variable_get('feed_item_length','Northland'), 
    '#required' => TRUE,
    '#options' => array (
        'Northland' => t('Northland'),
        'Auckland' => t('Auckland'),
        'Coromandel' => t('Coromandel'),
        'Waikato' => t('Waikato'),
        ), 
        '#description' => t('Select the region you currently live in'),
    );

$form['job_posting_workinnz'] = array(
    '#type' => 'radios',
    '#title' => t('Entitled to work in New Zealand'),
    '#requited' => TRUE,
    '#default_value' => variable_get('comment_preview', 0),
    '#options' => array(t('I have a work permit'), t('I require a work permit')),
  );
?>

Open in new window

0
Comment
Question by:dangaskin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:sam2912
ID: 33722801
So where's the HTML code? JavaScript does not work with PHP directly. PHP needs to print out the above as HTML code, and JavaScript can modify the HTML elements.
0
 

Author Comment

by:dangaskin
ID: 33723099
Everything is PHP in Drupal. The entire module that this came from is PHP. To get around this I was going to use print(). And print the JavaScript/HTML that is required. I however, have no understanding of what to 'print'.

Thanks,
Dan
0
 
LVL 4

Accepted Solution

by:
heppa earned 500 total points
ID: 33724404
Hi!

if you are using drupal, you might want to know, that things get a bit more complicated since you would not want to "hardcode" something, when using a CMS.

Have a look at this:
Adding Javascript to Drupal Modules

It means that you would add javascript that will then be added in the html output.

2 Hints:
first: make yourself familiar with simple HTML, then with simple HTML having JavaScript, then with simple PHP creating HTML, and finally with simple PHP creating simple HTML with simple Javascript! ;)

If you know all about that, you might recognize that CMS (like Drupal) do nothing else then creating HTML output. JavaScript can work in that HTML (eg. in the DOM). And if you know all that you might find the link I gave you useful, since you would have to rewrite the module you are using.

Best of luck!
Alex
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question