Welcome Guest, Not a member yet? Register   Sign In
How to use <button type=button>
#1

[eluser]Wondering Coder[/eluser]
Hi to all,

I'm usually Using input type submit eg: &lt;input type="submit" name="assign" value="Assign"/&gt;
and using this is no problem for me but now I want to use button eg:<button type="button" class="button" id="deleteb"><div><b>Assign Student</b></div></button>
but don't know how to used it or call it to my controller.


this is my controller function
Code:
function group_students()
    {
       $data['mod'] = strtolower(get_class($this));
        $assign_student = $this->input->post('assign');
        $maxMember = $this->admin_db->getGroupSetting();
        $countMember = $this->admin_db->countMembers($this->input->post('group'));
        
        $data['error'] = '';
                                        
        if($this->form_validation->run('group_students')===FALSE)
        {
            $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
        }
        else
        {
            if($assign_student)//&lt;input type="submit" name="assign" value="Assign"/&gt;
            {
                if($maxMember->max_members > $countMember)
                {
                    if($countMember+1 == 1)
                    {
                        $is_leader  = 1;
                    }
                    else
                    {
                        $is_leader = $this->input->post('is_leader');
                    }
                    $student = array(
                        'user_id' => $this->input->post('student'),
                        'group_no' => $this->input->post('group'),
                        'is_leader' => $is_leader
                        );
                        
                    $this->admin_db->save_group($student['group_no'],$student);  
                }
                else
                {
                    $data['max_error'] = "<p class='error'>Sorry, This group reached the maximum number of members!</p>";
                }  
            }
        
        }
        $cond = array('a.data_id'=> 1);
        $data['student_list'] = $this->admin_db->getUsers($cond);
        $data['group_setting'] = $this->admin_db->getGroupSetting();
        $data['cross_student'] = $this->admin_db->getGroup();
        $data['by_group'] = $this->admin_db->groupStudents();
        $data['countMember'] = $this->admin_db->countMembers($this->input->post('group'));
        
        $data['content'] = $this->load->view('admin/groups', $data, true);
        //$this->output->enable_profiler(TRUE);
        $this->load->vars($data);
        $this->load->view('admin/admin_template');
    }
#2

[eluser]theprodigy[/eluser]
What do you want the button to do? A button is just a button unless you have a handler listening for it's click event. You'll have to either add a onclick attribute to it, or handle it in javascript.
#3

[eluser]Wondering Coder[/eluser]
thanks for the rep theprodigy,

either the two is good. could you give me an example on how to do this. i'm pretty new to javascript scripting.
#4

[eluser]theprodigy[/eluser]
It all depends on what you want the button to do.
A simple script would be:
Code:
[removed]
function doSomething(id)
{
   alert(id)
}
[removed]
<button name="button" id="my_button">A Button</button>

But that's not very useful in production environment. What do you want your button to do?
#5

[eluser]Wondering Coder[/eluser]
why do you say that? You mean I will a future problem if i used buttons?
#6

[eluser]theprodigy[/eluser]
no, I'm saying having a function that alerts the id of the element (like my example) isn't useful in production environment.
#7

[eluser]Wondering Coder[/eluser]
ah, i don't think I'll be using an alert or something. What I just want is my button to direct it in my controller.
#8

[eluser]theprodigy[/eluser]
Quote:What I just want is my button to direct it in my controller.
What exactly do you mean by that? Like doing an ajax call? Submitting a form?
What do you mean by 'direct it in my controller'?
#9

[eluser]InsiteFX[/eluser]
html5 way: You will need to play with it.
Code:
// css code
.submit input
{
    margin: 0;
    padding: 5px 20px;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
    border: 0 none;
    color: #fff;
    background-color: #054C81;
    background-image: -webkit-gradient(linear, center bottom, center top, from(#054C81), to(#0595B3));
    background-image: -moz-linear-gradient(90deg, #054C81, #0595B3);
    font-size: 110%;
}

// HTML code
    <div class="submit">
        &lt;input name="submit" type="submit" value="Assign Student"&gt;
    </div>

InsitweFX
#10

[eluser]Wondering Coder[/eluser]
ok, sorry for not pointing, hehe. yes. when i clicked the button it will submit the form using button type.




Theme © iAndrew 2016 - Forum software by © MyBB